﻿<UserControl 
    x:Class="myManga_App.Views.SearchView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:vm="clr-namespace:myManga_App.ViewModels"
    xmlns:button="clr-namespace:myManga_App.Resources.Theme.Buttons"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:mangaObjects="clr-namespace:myMangaSiteExtension.Objects;assembly=myMangaSiteExtension"
    mc:Ignorable="d" 
    d:DesignHeight="480"
    d:DesignWidth="640" 
    Background="{DynamicResource window-background}" 
    Foreground="{DynamicResource window-foreground}"
    FocusManager.FocusedElement="{Binding ElementName=SearchBox}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/myManga;component/Resources/Localization/Dictionary_en-US.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/CoreResourceDictionary.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/Button/MetroButton.xaml"/>

                <ResourceDictionary Source="/myManga;component/Themes/ListBox/ListBoxes.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/ListBox/ListBoxItems.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/ScrollBar/ScrollBar.xaml"/>

                <ResourceDictionary Source="/myManga;component/Themes/ProgressBar/Spinner.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="100" MaxWidth="300"/>
            <ColumnDefinition Width="15"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="32px"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border 
                Grid.Row="0"
                TextElement.FontSize="16">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.InputBindings>
                        <KeyBinding Command="{Binding SearchSiteCommand}" Key="Return"/>
                        <KeyBinding Command="{Binding ClearSearchCommand}" Key="Esc"/>
                    </Grid.InputBindings>
                    <button:MetroButton
                        Grid.Column="0"
						FontFamily="{DynamicResource OpenIconic}"
						Content="{DynamicResource oi-magnifying-glass}"
                        Command="{Binding SearchSiteCommand}"
                        ToolTip="Search Sites"
                        Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                    <TextBox
                        x:Name="SearchBox"
                        Grid.Column="1" 
                        BorderBrush="{x:Null}" 
                        BorderThickness="0" 
                        Background="{x:Null}"
                        VerticalContentAlignment="Center"
                        Foreground="{DynamicResource window-foreground}"
                        Text="{Binding SearchFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <button:MetroButton
                        Grid.Column="3"
					    FontFamily="{DynamicResource OpenIconic}"
					    Content="{DynamicResource oi-delete}"
                        Command="{Binding ClearSearchCommand}"
                        ToolTip="Clear Search"
                        Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                </Grid>
            </Border>
            <ListBox
                x:Name="MangaList"
                Grid.Row="1"
                Background="{x:Null}"
                BorderBrush="{x:Null}"
                BorderThickness="0" 
                ItemContainerStyle="{DynamicResource SearchView_List_MangaListBoxItem}" 
                SelectedIndex="0"
                Visibility="{Binding HasItems, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}" 
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                SelectedItem="{Binding SelectedMangaObject}"
                ItemsSource="{Binding MangaCollection}"/>
            <ProgressBar 
                Grid.Row="1" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center" 
                Width="96" Height="96" 
                Style="{DynamicResource Spinner}" 
                Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}"
                >
                <ProgressBar.Foreground>
                    <SolidColorBrush Color="#BF000000"/>
                </ProgressBar.Foreground>
            </ProgressBar>
        </Grid>
        <Grid
            Grid.Column="2"
            Visibility="{Binding DataContext, ElementName=MangaObjectDescription, TargetNullValue=Collapsed}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="8"/>
                <RowDefinition Height="32"/>
                <RowDefinition Height="8"/>
            </Grid.RowDefinitions>
            <button:MetroButton
                Grid.Row="2"
                FontFamily="{DynamicResource OpenIconic}"
                Content="{DynamicResource oi-data-transfer-download}"
                ContentStringFormat="{}{0} Add to Library {0}"
                FontSize="18"
                Command="{Binding StoreMangaInfoCommand}"/>
            <Grid
                x:Name="MangaObjectDescription"
                DataContext="{Binding SelectedItem, ElementName=MangaList}"
                Background="{DynamicResource window-background}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <!--<ColumnDefinition MinWidth="100" MaxWidth="300"/>-->
                </Grid.ColumnDefinitions>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="332"/>
                        <RowDefinition Height="32"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="32"/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.ColumnSpan="2" Text="{Binding Name}" ToolTip="{Binding Name}" TextTrimming="WordEllipsis" FontWeight="Bold" FontSize="24" Margin="32,0,0,0"/>
                        <Grid 
                            Grid.Row="1" 
                            Grid.RowSpan="8"
                            Margin="0,0,3,0">
                            <Image Source="{Binding Converter={StaticResource LoadImageFromMangaArchive}}"/>
                        </Grid>
                        <StackPanel Grid.Row="1" Grid.Column="1">
                            <TextBlock Text="Alternate Titles:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding AlternateNames, Converter={StaticResource StringListToCSV}}" ToolTip="{Binding AlternateNames, Converter={StaticResource StringListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                        <StackPanel Grid.Row="2" Grid.Column="1">
                            <TextBlock Text="Released:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding Released, StringFormat=yyyy}" ToolTip="{Binding Released, StringFormat=yyyy}" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                        </StackPanel>
                        <StackPanel Grid.Row="3" Grid.Column="1">
                            <TextBlock Text="Type:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding MangaType, StringFormat={}{0}}" ToolTip="{Binding MangaType, StringFormat={}{0}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                        </StackPanel>
                        <StackPanel Grid.Row="4" Grid.Column="1">
                            <TextBlock Text="Authors:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding Authors, Converter={StaticResource StringListToCSV}}" ToolTip="{Binding Authors, Converter={StaticResource StringListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                        <StackPanel Grid.Row="5" Grid.Column="1">
                            <TextBlock Text="Artists:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding Authors, Converter={StaticResource StringListToCSV}}" ToolTip="{Binding Authors, Converter={StaticResource StringListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                        <StackPanel Grid.Row="6" Grid.Column="1">
                            <TextBlock Text="Genres:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding Genres, Converter={StaticResource StringListToCSV}}" ToolTip="{Binding Genres, Converter={StaticResource StringListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                        <StackPanel Grid.Row="7" Grid.Column="1" Grid.RowSpan="2">
                            <TextBlock Text="Sites:" FontWeight="Bold" Foreground="{DynamicResource text-muted}"/>
                            <TextBlock Text="{Binding Locations, Converter={StaticResource LocationListToCSV}}" ToolTip="{Binding Locations, Converter={StaticResource LocationListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                            <TextBlock Text="{Binding DatabaseLocations, Converter={StaticResource LocationListToCSV}}" ToolTip="{Binding DatabaseLocations, Converter={StaticResource LocationListToCSV}}" FontWeight="Bold" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                    </Grid>
                    <Grid Grid.Row="1"></Grid>
                    <ScrollViewer Grid.Row="2">
                        <TextBlock 
                            Text="{Binding Description}"
                            TextWrapping="WrapWithOverflow"
                            TextTrimming="CharacterEllipsis"
                            FontSize="16"
                            MinHeight="100"/>
                    </ScrollViewer>
                </Grid>
                <!--<ListBox 
				    Grid.Column="1"
				    ItemsSource="{Binding Chapters}" 
				    ItemContainerStyle="{DynamicResource SearchView_ChapterListBoxItem}"
				    Visibility="{Binding HasItems, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}" 
				    ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch"/>-->

            </Grid>
        </Grid>
    </Grid>
</UserControl>
